package com.happyfamily.springboot.crowdsourcingplatform.controller.weng;

import com.happyfamily.springboot.crowdsourcingplatform.base.result.PageTableRequest;
import com.happyfamily.springboot.crowdsourcingplatform.base.result.Results;
import com.happyfamily.springboot.crowdsourcingplatform.dto.LogDto;
import com.happyfamily.springboot.crowdsourcingplatform.model.OperationLog;
import com.happyfamily.springboot.crowdsourcingplatform.service.weng.LogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/api-back/log")
@Slf4j
public class LogController
{
	@Autowired
	LogService logService;

	@GetMapping("/list")
	@ResponseBody

	public Results<OperationLog> getAllLogsByPage(PageTableRequest request)
	{
		request.countOffset();
		return logService.getAllLogsByPage(request.getOffset(), request.getLimit());
	}

	@GetMapping("/delete")
	@ResponseBody
	@PreAuthorize("hasAuthority('back:log:delete')")
	public Results<OperationLog> delete(LogDto logDto)
	{
		logService.deleteLog(logDto.getId());
		return Results.success();
	}


	@GetMapping("/findLogByFuzzy")
	@ResponseBody
	public Results<OperationLog> getLogByFuzzy(PageTableRequest requests, String operationType, String logDescribe, String startTime, String endTime)
	{
		System.out.println(1111);
		requests.countOffset();
		return logService.getLogByFuzzy(logDescribe, operationType, startTime, endTime, requests.getOffset(), requests.getLimit());
	}

}
